//
//  UIImageView+CycleExtension.m
//  iOSHeartAnimation
//
//  Created by ddy on 2018/8/10.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "UIImageView+CycleExtension.h"

@implementation UIImageView (CycleExtension)
/**
 * 1.用UIGraphics配合UIBezierPath绘制圆形图片
 */
- (void)cycle_circleImageView {
    
    //开始绘制
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0);
    //画圆形
    [[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.bounds.size.width] addClip];
    [self drawRect:self.bounds];
    //获取裁截后的图片
    self.image = UIGraphicsGetImageFromCurrentImageContext();
    //结束绘制
    UIGraphicsEndImageContext();
}
/**
 * 2.用CAShapeLayer配合UIBezierPath绘制圆形图片
 */
- (void)cycle_circleImageViewWithBezier {
    //获取路径
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:self.bounds.size];
    //shapeLayer
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = self.bounds;
    shapeLayer.path = bezierPath.CGPath;
    //设置图片layer
    self.layer.mask = shapeLayer;
    
    
}






@end
